package com.hmob.hmdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.LinearLayout;

import com.hmob.hmsdk.ads.AdError;
import com.hmob.hmsdk.ads.splash.HMSplash;
import com.hmob.hmsdk.ads.splash.SplashListener;

public class SplashBottomActivity extends AppCompatActivity {
    public static String TAG = SplashActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_bottom);
        LinearLayout container = findViewById(R.id.container);

        new HMSplash(Constants.ADID_SPLASH, container, new SplashListener() {
            @Override
            public void onNoAd(AdError error) {
                Log.e(TAG, error.getErrorMessage());
                // 如果加载广告失败，则直接跳转
                startActivity(new Intent(SplashBottomActivity.this, MainActivity.class));
                finish();
            }

            @Override
            public boolean onReceived(boolean prior) {
                return true;
            }

            @Override
            public void onADPresent() {
                Log.i(TAG, "onADPresent");
            }

            @Override
            public void onADDismissed() {
                Log.i(TAG, "onADDismissed");
                // 如果加载广告失败，则直接跳转
                startActivity(new Intent(SplashBottomActivity.this, MainActivity.class));
                finish();
            }

            @Override
            public void onADClicked() {
                Log.i(TAG, "onADClicked");
            }

            @Override
            public void onADTick(int time) {
                Log.i(TAG, String.valueOf(time));
            }
        }).load(this);

    }

    //防止用户返回键退出APP
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
